<script setup>
import { ref, onMounted } from 'vue';

const getImageUrl = (user) => {
  return new URL(`../assets/images/${user}.jpg`, import.meta.url).href;
};

// 假设这是从后端获取的用户数据
const user = ref({
  name: '',
  role: '', // 新增角色字段
});

onMounted(() => {
  // 从localStorage中获取用户名
  const username = localStorage.getItem('username');
  if (username) {
    user.value.name = username;
    user.value.role = username === 'wkl' ? '超级管理员' : '普通管理员'; // 根据用户名设置角色
  }
});
</script>

<template>
  <div class="personal-center">
    <div class="avatar">
      <img :src="getImageUrl('user')" class="user" />
    </div>
    <div class="user-info">
      <h2>{{ user.name }}</h2>
      <p>{{ user.role }}</p> <!-- 显示管理员级别 -->
    </div>
  </div>
</template>

<style lang="less" scoped>
.personal-center {
  display: flex;
  align-items: center;
  padding: 20px;

  .avatar {
    img {
      width: 100px;
      height: 100px;
      border-radius: 50%;
      object-fit: cover;
    }
  }

  .user-info {
    margin-left: 20px;

    h2 {
      margin: 0;
      font-size: 24px;
    }

    p {
      margin: 10px 0 0;
      font-size: 16px;
    }
  }
}
</style>
